package book.ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperations implements IOperations{
    public void work(BookList bookList){
        System.out.println("归还图书...");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的图书名：");
        String name = scanner.nextLine();

        int currentsize = bookList.getUsedSize();

        for (int i = 0; i < currentsize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                if (book.isBorrowed()) {
                    System.out.println("归还成功！");
                    book.setBorrowed(false);
                    return;
                }
            }
            System.out.println("未找到此书，归还失败！");
        }
    }
}
